<template>
	<section>
		<!--工具条-->
		<el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
			<el-form :inline="true" :model="filters">
				<el-form-item>
					<el-input v-model="filters.comName" placeholder="比赛名称"></el-input>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" v-on:click="getCom">查询</el-button>
					<el-button type="info" v-on:click="resetquery">清空</el-button>
				</el-form-item>
			</el-form>
		</el-col>

		<!--列表-->
		<el-table :data="comlist" highlight-current-row v-loading="listLoading" @selection-change="selsChange" style="width: 100%;">
			<el-table-column prop="comName" label="比赛名称" width="180" sortable>
			</el-table-column>
			<el-table-column prop="comLevel" label="级别" width="100" :formatter="formatReLevel" sortable>
			</el-table-column>
			<el-table-column prop="startDate" label="起始日期" width="160" sortable>
			</el-table-column>
			<el-table-column prop="endDate" label="结束日期" width="160">
			</el-table-column>
			<el-table-column prop="address" label="比赛地点" min-width="180">
			</el-table-column>
			<el-table-column label="操作" width="150">
				<template slot-scope="scope">
					<el-button size="small" @click="gamedetail(scope.$index, scope.row)">查看</el-button>
				</template>
			</el-table-column>
		</el-table>

		<!--工具条-->
		<el-col :span="24" class="toolbar">
			<el-pagination layout="prev, pager, next" @current-change="handleCurrentChange" :page-size="10" :total="total" style="float:right;">
			</el-pagination>
		</el-col>

	</section>
</template>

<script>
	import util from '../../common/js/util'
	//import NProgress from 'nprogress'
	import {getComList, getComLeve, getPositionLeve} from '../../api/api';

	export default {
		data() {
			return {
				recomlevel: [],
				recomleveldict:{},
				repositionlevel:[],
				repositionleveldict:{},
				filters: {
					comName: ''
				},
				comlist: [],
				total: 0,
				page: 1,
				listLoading: false,
				sels: [],//列表选中列
				editLoading: false,
				addLoading: false,
			}
		},
		methods: {
			formatReLevel (row) {
				return this.recomleveldict['lv'+row.comLevel];
			},
			handleCurrentChange(val) {
				this.page = val;
				this.getCom();
			},
			resetquery(){
				this.filters.comName = '';
				this.getCom();
			},
			// 查看比赛详情
			gamedetail(index, row){
				
			},
			//获取比赛列表
			getCom() {
				console.log('get')
				let para = {
					page: this.page,
					comName: this.filters.comName,
					pageSize: 10
				};
				this.listLoading = true;
				//NProgress.start();
				getComList(para).then((res) => {
					this.total = res.data.data.total;
					this.comlist = res.data.data.list;
					this.listLoading = false;
					//NProgress.done();
				})
				.catch((error) =>{

				})
				;
			},
			selsChange: function (sels) {
				this.sels = sels;
			},
			handleEdit (index, row) {
				this.$router.push({path: '/editEvents',query: {comId: row.id}});
			},
			applygame(){
				
			}
		},
		mounted() {
			console.log('ddd');
			// 初始化赛事级别
    getComLeve()
      .then(res => {
        if (res.data.code === "0000") {
          this.recomlevel = res.data.data.list.filter(level => {
            return level.isDel === 0;
          });
          this.recomlevel.forEach(level => {
            if (level.isDel === 0) {
              this.recomleveldict["lv" + level.id] = level.dictName;
            }
					});
					// 初始化赛事等级后 再请求赛事列表
					this.getCom();

        }
      })
      .catch(err => {});
    // 初始化职务级别
    getPositionLeve()
      .then(res => {
        if (res.data.code === "0000") {
          this.repositionlevel = res.data.data.list.filter(level => {
            return level.isDel === 0;
          });
          this.repositionlevel.forEach(level => {
            if (level.isDel === 0) {
              this.repositionleveldict["lv" + level.id] = level.dictName;
            }
          });
        }
      })
      .catch(err => {});

		}
	}

</script>

<style scoped>

</style>